#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10,M=1e6+10;
int T,n,m,L,k,p[N],vis[M],pre[M];
struct node{
	int l,r;
	node(){};
	node(const int tl,const int tr):l(tl),r(tr){};
	inline bool operator < (const node &other){
		return ((r!=other.r)?(r<other.r):(l<other.l));
	}
}a[N];
signed main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	int d,v,del,tmp,cnt,ans,sum;
	scanf("%d",&T);
	while(T--){
		scanf("%d%d%d%d",&n,&m,&L,&k);
		cnt=ans=sum=0;
		for(int i=1;i<=n;++i){
			scanf("%d%d%d",&d,&v,&del);
			if(del==0){
				if(v<=k)continue;
				a[++cnt]=node(d,L);
			}else if(del<0){
				if(v<=k)continue;
				if((k*k-v*v)%(2*del))tmp=(k*k-v*v)/(2*del);
				else tmp=(k*k-v*v)/(2*del)-1;
				a[++cnt]=node(d,min(d+tmp,L));
			}else if(del>0){
				if(v>k){
					a[++cnt]=node(d,L);
					continue;
				}
				tmp=(k*k-v*v)/(2*del)+1;
				if(d+tmp>L)continue;
				a[++cnt]=node(d+tmp,L);
			}
		}
		sort(a+1,a+cnt+1);
		for(int i=1;i<=m;++i){
			scanf("%d",&p[i]);
			vis[p[i]]=1;
		}
		pre[0]=vis[0];
		for(int i=1;i<=L;++i)pre[i]=pre[i-1]+vis[i];
		for(int i=1,j=0;i<=cnt;++i){
			if(pre[a[i].r]- ((a[i].l)?(pre[a[i].l-1]):0) ==0)continue;
			++sum;
			if(j && a[i].l<=p[j])continue;
			while(j<=m && p[j]<=a[i].r)++j;
			--j,++ans;
		}
		printf("%d %d\n",sum,m-ans);
		for(int i=1;i<=m;++i)vis[p[i]]=0;
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
